/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.wallet.online.jwt;

import java.util.HashMap;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.wallet.online.jwt.util.GsonHelper;

/**
 * Full Wallet Request Java object representation
 * 
 * https://devsite.googleplex.com/
 * payment-express/api-reference#jwt-requests-and-responses
 * 
 * @author pying(peng ying)
 * 
 */
public class FullWalletRequest extends JWTRequest {

  private final String TYPE = "google/wallet/online/full/v2/request";
  private final String AUD = "Google";

  private FullWalletBody request;

  /**
   * Constructor that takes Merchant Id and Secret as parameters
   * 
   * @param iss
   *          Merchant Id to be used as issuer
   * @param merchantSecret
   *          Merchant Secret
   */
  public FullWalletRequest(FullWalletBody body) {
    setRequest(body);
    setType(TYPE);
    setAudience(AUD);
  }

  /**
   * Converts Object to HashMap to add in JWT payload
   * 
   * @return HashMap of JWT content
   */
  public HashMap<String, JsonElement> getContent() {
    Gson gson = GsonHelper.getGson();
    JsonObject obj = gson.toJsonTree(getRequest()).getAsJsonObject();
    HashMap<String, JsonElement> content = new HashMap<String, JsonElement>();
    content.put("request", obj);
    return content;
  }

  public FullWalletBody getRequest() {
    return request;
  }

  public void setRequest(FullWalletBody request) {
    this.request = request;
  }
}
